//
//  EventTimeView.m
//  CJMobile
//
//  Created by wh15113030 on 16/4/5.
//  Copyright © 2016年 长江证券. All rights reserved.
//

#define FONT(font)  [UIFont systemFontOfSize:font]


#define label_width 80
#define padding 10
#define timeBtn_width 45
#define subview_height 44
#define label_font 15
#define buttonTime_font 15

#define arrow_padding 30
#define arrow_width 15


#import "EventTimeView.h"


@interface EventTimeView()

@property (nonatomic, strong) UIView *backView;

@property (nonatomic, copy) NSString *startTime;

@property (nonatomic, copy) NSString *endTime;

@end


@implementation EventTimeView
- (instancetype)initWithFrame:(CGRect)frame startTime:(NSString *)startTime endTime:(NSString *)endTime{
    self= [super initWithFrame:frame];
    if (self) {
        
        self.startTime = startTime;
        self.endTime = endTime;
        
        [self addView];
    }
    return self;
}

- (void)addView{
    
    NSArray *starTime = @[@"开始时间",@"结束时间"];
    
    for (NSInteger i = 0; i < 2; i ++) {
        NSString *text = starTime[i];
        NSString *time;
        if (i == 0) {
            time = self.startTime;
        }else if(i == 1){
            time = self.endTime;
        }
        
        if (i == 0) {
            UIView *backView = [self backView:text btnText:time btnTag:i];
            self.backView = backView;
            [self addSubview:self.backView];
//            [self setupButtonMarsy:backView];
        }else{
            UIView *backView = [self backView:text btnText:time btnTag:i];
            self.backView = backView;
            [self addSubview:self.backView];
//            [self setupButtonMarsy1:backView];
        }
        
        
    }
    
    //创建箭头
    UIImageView *arrowView = [[UIImageView alloc] init];
    arrowView.image = [UIImage imageNamed:@"icon_CD_Arrow"];
    arrowView.contentMode = UIViewContentModeScaleAspectFit;
    arrowView.frame = CGRectMake(0, 0, arrow_width, arrow_width);
    arrowView.centerX = [UIScreen mainScreen].bounds.size.width * 0.5 + padding * 0.5;
    arrowView.centerY = self.height * 0.5;
    
    [self addSubview:arrowView];
    
}


//- (void)setupButtonMarsy:(UIView *)view{
//    [view mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self).offset(padding * 1.5);
//        make.right.equalTo(self).offset(-(KScreenWidth * 0.5 + arrow_width * 0.5));
//        make.top.equalTo(self);
//        make.bottom.equalTo(self);
//    }];
//}
//
//- (void)setupButtonMarsy1:(UIView *)view{
//    [view mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self).offset((KScreenWidth * 0.5 + arrow_width * 0.5 + padding));
//        make.right.equalTo(self).offset(0);
//        make.top.equalTo(self);
//        make.bottom.equalTo(self);
//    }];
//}


- (UIView *)backView:(NSString *)text btnText:(NSString *)btnText btnTag:(NSInteger *)tagIndx{
    
    UIView * backView = [[UIView alloc] init];
    //时间的标题
    UILabel *label = [[UILabel alloc] init];
    
    label.frame = CGRectMake(padding * 0.5, 0, label_width , subview_height);
    
    label.text = text;
    label.font = FONT(label_font);
    label.textAlignment = NSTextAlignmentCenter;
//    label.textColor = UIColorFromRGB(9a, 9a, 9a);
    
    [backView addSubview:label];
    
    UIButton *button = [[UIButton alloc] init];
    
//    button.titleLabel.font = FONT(buttonTime_font);
    
    
//    button.tag = tagIndx;
    button.frame = CGRectMake(CGRectGetMaxX(label.frame), 0, label_width - padding * 0.5, subview_height);
    [button addTarget:self action:@selector(clickBtnSelecteTime:) forControlEvents:UIControlEventTouchUpInside];
    
    [button setTitle:btnText forState:UIControlStateNormal];
    
//    button.titleLabel.textColor = UIColorFromRGB(05, 05, 05);
    
    button.contentEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
    
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

    
    [backView addSubview:button];
    
    return backView;
}

-(void)clickBtnSelecteTime:(UIButton *)btn{
    if (self.btnTimeBlock) {
        self.btnTimeBlock(btn.tag);
    }
}

@end
